﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using DynSim.EntityFramework;
using DynSim.Basics;

namespace DynSim.Entities
{
    [Serializable]
    public class ControlsHandler : IEntity
    {
        public string name { get; set; }

        BaseEngine engine;
        public List<Control> controls;

        public void AddControl(Control control)
        {
            this.controls.Add(control);
        }

        public ControlsHandler(BaseEngine engine, string name)
        {
            this.name = name;

            this.engine = engine;
            controls = new List<Control>();
        }

        public void Draw(GameTime gameTime)
        {

        }

        public void Initialize()
        {
            
        }

        public void Update(GameTime gameTime)
        {
            if (engine != null)
            {
                foreach (Control control in controls)
                {
                    if (Keyboard.GetState().IsKeyDown(control.keyboardButton))
                    {
                        control.buttonPressedEventHandler.Invoke(this, new EventArgs());
                    }
                }
            }
            
        }
        
        public void Show()
        {
            throw new NotImplementedException();
        }

        public void Hide()
        {
            throw new NotImplementedException();
        }
    }

    [Serializable]
    public class Control
    {
        public Keys keyboardButton;
        public Buttons gamePadButton;
        public EventHandler buttonPressedEventHandler;

        public Control(Keys keyboardButton, Buttons button)
        {
            this.keyboardButton = keyboardButton;
            this.gamePadButton = button;
        }
    }
}
